<?php

use yii\widgets\LinkPager;
use yii\helpers\Html;
use yii\helpers\Url;

?>

<div style="height:5px"></div>
<div class="btn-group" style="float: right;">
    <a href="<?=Url::toRoute(['role/addrole']);?>" class="btn btn-warning">添加角色</a>
</div>
<table id="dnd-example" cellspacing="0" class="table table-striped table-hover">
        <thead>
            <tr>
                <th style="width:80px;">ID</th>
                <th>角色名称</th>
                <th>角色描述</th>
                <th>角色启用</th>
                <th>操作</th>
            </tr>
        </thead>
        <tbody>

        <?php
        $roles=$dataProvider->getModels();    
        foreach($roles as $role)
        {
        ?>
        
            <tr id="role_<?=$role->roleid;?>">
                <td scope="row"><?= $role->roleid;?></td>
                <td><?= $role->rolename;?></td>
                <td><?= $role->description;?></td>
                <td><?= $role->whetherDisabled();?></td>
                <td>
                    
                    <a onclick="dis(<?=$role->roleid?>)">
                        <button type="button" class="btn btn-info">启用/禁用</button>
                    </a>
                    <a onclick="load(<?=$role->roleid?>)">
                        <button type="button" class="btn btn-default">权限设置</button>
                    </a>
                    <a onclick="loading(<?=$role->roleid?>)">
                        <button type="button" class="btn btn-primary">栏目设置</button>
                    </a>
                    <a href="<?= Url::toRoute(['role/rolemember', 'roleid' => $role->roleid]); ?>">
                        <button type="button" class="btn btn-warning">成员管理</button>
                    </a>
                    <a href="<?= Url::toRoute(['role/updaterole', 'roleid' => $role->roleid]);?>">
                        <button type="button" class="btn btn-success">编辑</button>
                    </a>
                    <a onclick="del(<?=$role->roleid?>)">
                        <button type="button" class="btn btn-danger">删除</button>
                    </a>
                </td>
            </tr>
        
        <?php }?>
        </tbody>
    </table> 
                    <?php 
                    $pages=$dataProvider->getPagination();
                    echo LinkPager::widget([
                    'pagination' => $pages,
                    ]);
                    ?>
            </div><!-- /.col-sm-12 -->
        </div><!-- content -->
    </div><!-- row -->
</div>

<?php $this->beginBlock('opt') ?>

//    删除角色
    function del(roleid)
    {
        layer.confirm(
            '确定删除该角色？',
            {icon: 5, title:'删除'},
            function(index){
                $.get("<?=Url::toRoute(['role/deleterole'])?>", {roleid:roleid},
                    function(data){
                    if(data.status == -1){
                    $("#role_"+roleid).hide();
                }
            layer.msg(data.msg);
            });
            layer.close(index);
        });
    }
//    更改角色状态
    function dis(roleid)
    {
        layer.confirm(
            '确定更改该角色状态？',
            {icon: 1, title:'更改状态'},
            function(disabled){
                $.get("<?=Url::toRoute(['role/statusrole'])?>", {roleid:roleid},
                    function(data){
                    layer.msg(data.msg);
                    window.location.reload();
                });
            layer.close(disabled);
        });
    }
//   赋予权限
    function load(roleid)
    {
        layer.open({
            type: 2,
            title:'权限设置',
            closeBtn: 1, //不显示关闭按钮
            shadeClose: true,
            shade: false,
            area: ['1100px', '600px'],
            maxmin: true, //开启最大化最小化按钮
            content: '<?=Url::toRoute(['role/setsite'])?>?roleid='+roleid, //iframe的url，no代表不显示滚动条
        
        });
    }
    //   赋予权限
    function loading(roleid)
    {
        layer.open({
            type: 2,
            title:'权限设置',
            closeBtn: 1, //不显示关闭按钮
            shadeClose: true,
            shade: false,
            area: ['1100px', '600px'],
            maxmin: true, //开启最大化最小化按钮
            content: '<?=Url::toRoute(['role/set'])?>?roleid='+roleid, //iframe的url，no代表不显示滚动条
        
        });
    }
<?php $this->endBlock() ?>
<?php $this->registerJs($this->blocks['opt'], \yii\web\View::POS_END);?>